package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcBsEmrStructEntity;
import com.dhcc.cdc.busi.service.ICdcBsEmrStructService;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 电子病历语义分析解析后结果
 * 
 * @ClassName: CdcBsEmrStructController
 * @Description: TODO
 * @author sunyingjie
 * @date 2023-03-16 10:26:09
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcbsemrstruct")
public class CdcBsEmrStructController extends BaseController {

	private String PREFIX = "/backend/busi/cdcbsemrstruct/";

	@Autowired
	private ICdcBsEmrStructService cdcBsEmrStructService;
	

    /**
     * 跳转到电子病历语义分析解析后结果列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "cdcbsemrstruct.html";
    }
	
    /**
     * 跳转到新增电子病历语义分析解析后结果
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "cdcbsemrstruct_add.html";
    }
	
	/**
     * 跳转到修改电子病历语义分析解析后结果
     */
    @RequestMapping("/to_update/{cdcBsEmrStructId}")
    public String toUpdate(@PathVariable Integer cdcBsEmrStructId, Model model) {
        CdcBsEmrStructEntity cdcBsEmrStruct = this.cdcBsEmrStructService.selectById(cdcBsEmrStructId);
        model.addAttribute("cdcBsEmrStruct",cdcBsEmrStruct);
        return PREFIX + "cdcbsemrstruct_edit.html";
    }

    /**
     * 获取电子病历语义分析解析后结果列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcBsEmrStructEntity> page = new PageFactory<CdcBsEmrStructEntity>().defaultPage();
        List<CdcBsEmrStructEntity> result = this.cdcBsEmrStructService.page(page,params);
        page.setRecords((List<CdcBsEmrStructEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增电子病历语义分析解析后结果
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(CdcBsEmrStructEntity cdcBsEmrStruct) {
        if (CommonUtil.isOneEmpty(cdcBsEmrStruct)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.cdcBsEmrStructService.insert(cdcBsEmrStruct);
        return R.ok();
    }

    /**
     * 删除电子病历语义分析解析后结果
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer cdcBsEmrStructId) {
	
        this.cdcBsEmrStructService.deleteById(cdcBsEmrStructId);

        return R.ok();
    }

    /**
     * 修改电子病历语义分析解析后结果
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(CdcBsEmrStructEntity cdcBsEmrStruct) {
        if (CommonUtil.isOneEmpty(cdcBsEmrStruct)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.cdcBsEmrStructService.updateById(cdcBsEmrStruct);
        return R.ok();
    }

    /**
     * 获取电子病历语义分析解析后结果
     */
    @RequestMapping(value = "/getStructResult")
    @ResponseBody
    public Object getStructResult(@RequestParam Map<String, Object> params) {
        CdcBsEmrStructEntity emrStructEntity = this.cdcBsEmrStructService.selectOne(new EntityWrapper<CdcBsEmrStructEntity>().eq("emr_id", params.get("emrId")));
        if (emrStructEntity != null) {
            return emrStructEntity;
        } else {
            return null;
        }
    }
	
}
